package org.jeeasy.system.modules.user.domain.model;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.URL;
import org.jeeasy.common.core.annotation.convert.BeanTransfer;
import org.jeeasy.common.core.annotation.dict.Dict;
import org.jeeasy.common.core.base.convert.BaseConverter;
import org.jeeasy.common.core.base.convert.BaseTransfer;
import org.jeeasy.common.core.config.valid.group.UpdateGroup;
import org.jeeasy.common.core.config.valid.validator.ValidatorPattern;
import org.jeeasy.system.enums.user.SysUserStatusEnum;
import org.jeeasy.system.modules.user.domain.SysUser;
import org.mapstruct.Mapper;

import java.time.LocalDate;

/**
 * UserInfoModel: 保存用户 数据模型
 *
 * @author AlpsDDJ
 * @version v1.0
 * @date 2020/11/21 22:11
 */
@Data
@Schema(description = "保存用户 数据模型")
public class UserInfoModel {


    //@Schema(description = "longTest")
    //private Long longTest;
    //
    //
    //@Schema(description = "bigDecimalTest")
    //private BigDecimal bigDecimalTest;


    @Valid
    @Schema(description = "用户信息")
    private UserModel user;

    @Schema(description = "用户角色")
    private String[] roles;

    @Schema(description = "用户部门")
    private String[] depts;

    @Data
    @BeanTransfer(UserInfoModel.Converter.class)
    @EqualsAndHashCode(callSuper = true)
    public static class UserModel extends BaseTransfer<SysUser> {

        @Schema(description = "ID")
        @NotBlank(message = "id不能为空", groups = {UpdateGroup.class})
        private String id;

        @Schema(description = "用户名")
        @Length(min = 2, max = 20, message = "用户名长度2-20位")
        private String username;

        @Schema(description = "电话号码")
        @Pattern(regexp = ValidatorPattern.MOBILE_PHONE, message = ValidatorPattern.MOBILE_PHONE_MSG)
        private String phone;

        @Schema(description = "真实姓名")
        private String realName;

        @Schema(description = "性别", example = "1: 男, 0: 女")
        @Max(value = 1, message = ValidatorPattern.SEX_MSG)
        @Min(value = 0, message = ValidatorPattern.SEX_MSG)
        private Integer sex;

        @Schema(description = "生日")
        private LocalDate birthday;

        @Schema(description = "状态")
        @Dict(dictEnum = SysUserStatusEnum.class)
        private Integer status;

        @Schema(description = "邮箱")
        @Email(message = ValidatorPattern.EMAIL_MSG)
        private String email;

        @Schema(description = "头像")
        @URL(message = "头像图片地址错误")
        private String avatar;

        @Schema(description = "备注")
        private String remark;
    }


    @Mapper
    public interface Converter extends BaseConverter<SysUser, UserInfoModel.UserModel> {

    }
}
